package com.upup.cloud.chhk_gj.utils.ch;


import com.upup.cloud.chhk_gj.utils.Base64Utils;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import javax.crypto.spec.DESedeKeySpec;
import javax.crypto.spec.IvParameterSpec;
import java.io.UnsupportedEncodingException;
import java.security.Key;
import java.security.SecureRandom;
import java.security.spec.KeySpec;

public class DESUtils {
    public static final String b ="spring20140530airlines!)";
    public static final String v ="12345678";

    public static void main(String[] args) {
        try {
            String str ="OI2FprGJGkD+qFr4K1VdePhN7Cj8vkKUnisEu4nRssLP3YqCDfrdxfDOiD6mLz+FMkFJRqALxRicOFSee3aP2G92Blty+ujH+IFMcBe/IpONIlpCPClCpHFaIgkEtQOSnOO9/cJbbTi8I08nANiVY1+RMTXlsf6UG7jwN2MtVCwV2wU1dMS1zRF1VrIhoaXcxLI9CjeBOZM4dFr3FlfDfp9AkWYMY3xdMMxTxONyHME8F4U7rGr6bXkbIVl/nkYfMODkf1usXHRxTfJndBwVOnSLhl1yCfsUZIh0ibdyAMSrlrDPUOK9o9bUupuhfiPdn3YWOpgf7P1KiOBLy6dbQ9iNtKyh2VNTwfloUpce08pRyxxFku5OsEj/Psqi0Exhbq0LpHc+Qx2CYJwychinf9Jw6hvo00WN1vLejzVMP3j5oHOQNnB3aFbKM8osHbZON83AZtt5yPU93IH1Yi2qw40wNeOLmXapKg0ol7w6rdPxUGau/TAxyi1w8SW9BWJjiY6/K13lyC7uYFBcZatS9wYiZ9+0CTCBhY3IpShOdYoCECNlZx0QtS/qAdnSx0eOcXuUSnuy/XVnnNxHBVrEshLsWNC5QrhFCZtuqX8TgjBBE/t4cuLzaT5QxlnR2o2NZTfts1NIVkuYxOHIyvq08BWmvXuMjPU/FOuDzb85TYpjNY15g9csr2N9k6MtLO1Cyzg8766vqVBAGGEBMQSBAycQT5NbLf9km2CCHN0NA4d67VDYjxb+B8qO3yRhxFjsVq97wAkOnec=";
//            String str =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oKRG9nQLgHG1EYHbU1mKG%2Ba1XbuR9YwJzaPzHK9Re0H%2BvU4gCmxMxzgK8aDyL0DDaOR60mzFfeoOIAT5NhBiYMkeINPLtWyVKZtZTxXFS8E%2FiUW2tiwzxWWjt3PyADkLUEn5BfWD8FPxaZm%2FOaKGGusopcfXYp9oywDbM3L996SF7zHISiA%2FDw9uZFMP5DzpHBm26wBXlSQ4tbccsorpW4JUWFIUlFp8S5Rd0%2FtC%2FqiSSOlc3bfrceUm1prsxUK3ZrE23lSsHo2AO386NbT71H46DttB8tu99CEIVJ6b5HKkCmgdbAmIF7xNCkez%2Fv2r3CGqloyEIeBlKkhGgRG%2FXe4sCD4rUo6ii1SWg1s6i%2F%2B8U6KwYdKmkx6M2QwAw%2Bze4OD3DIYw0B%2F0as%2FOskRe7bRrU6GFxRyU4fodHDL%2FEp8mCHj%2FclMoO45zyXA45xLoJc%2Bje6o7702%2FBHXFlyVIG5HVtYxDqucUhiErrWdvt4C8ibmMnLITEk3uwhvMS7X3lXUYeAib1nlz0qvzCWdiKgY02bRF2fFhNCdAur6CRUcDigw%2B0jxBkOlFq8oaryWzHilUuAuB%2Bif9kC62mtSAmIwFaN8gSdviplMco7wBIum4v9BKQh52qc5XosPyijnUtU0jiWXhCxb5nTU7LWCqesVC63vSexAtBjcE4%3D", "UTF-8");
            String ss = decode(str);
            System.err.println(ss);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public static String encode(String paramString1) throws Exception
    {
        Object localObject = new DESedeKeySpec(b.getBytes());
        localObject = SecretKeyFactory.getInstance("desede").generateSecret((KeySpec)localObject);
        Cipher localCipher = Cipher.getInstance("desede/CBC/PKCS5Padding");
        localCipher.init(1, (Key)localObject, new IvParameterSpec(v.getBytes()));
        return Base64Utils.encode(localCipher.doFinal(paramString1.getBytes("utf-8")));
    }

    public static String decode(String paramString1) throws Exception {
        Object localObject = new DESedeKeySpec(b.getBytes());
        localObject = SecretKeyFactory.getInstance("desede").generateSecret((KeySpec)localObject);
        Cipher localCipher = Cipher.getInstance("desede/CBC/PKCS5Padding");
        localCipher.init(2, (Key)localObject, new IvParameterSpec(v.getBytes()));
        return new String(localCipher.doFinal(Base64Utils.decode(paramString1)), "utf-8");
    }

    public static String decode(String paramString1, String paramString2) throws Exception
    {
        try
        {
            SecureRandom localSecureRandom = new SecureRandom();
            DESKeySpec param = new DESKeySpec(paramString2.getBytes("UTF-8"));
            SecretKey paramStr = SecretKeyFactory.getInstance("DES").generateSecret(param);
            Cipher localCipher = Cipher.getInstance("DES");
            localCipher.init(2, paramStr, localSecureRandom);
            return new String(localCipher.doFinal(paramString1.getBytes()));
        }
        catch (Exception paramStr) {
            System.err.println(paramStr.getMessage());
        }
        return "";
    }
    private static byte[] bs(String paramString) throws Exception
    {
        Object localObject2 = null;
        Object localObject1 = localObject2;
        try
        {
            byte[] arrayOfByte = paramString.getBytes("UTF-8");
            localObject1 = localObject2;
            if (arrayOfByte.length % 2 != 0)
            {
                localObject1 = localObject2;
                throw new IllegalArgumentException("Invalid hex string");
            }
            localObject1 = localObject2;
            byte[] param = new byte[arrayOfByte.length / 2];
            int i = 0;
            for (;;)
            {
                localObject1 = param;
                localObject2 = param;
                if (i >= arrayOfByte.length) {
                    break;
                }
                localObject1 = param;
                localObject2 = new String(arrayOfByte, i, 2);
                localObject1 = paramString;
                param[(i / 2)] = ((byte)Integer.parseInt((String)localObject2, 16));
                i += 2;
            }

            System.err.println(new String((byte[])localObject2));
            return (byte[])localObject2;
        }
        catch (UnsupportedEncodingException param)
        {
            System.err.println("Aa");
            localObject2 = localObject1;
        }
        System.err.println("Aa");
        return null;
    }
}
